#定义对象层库
import allure
from selenium.webdriver.common.by import By

from base.base import BasePage,BaseHandle
from utils import UtilsDriver


class LoginPage(BasePage):
    def __init__(self):
        super().__init__()
        #输入用户名
        self.username = By.ID,"mat-input-5"
        #输入密码
        self.password = By.ID,"mat-input-6"
        #点击登录按钮
        self.login_btn = By.XPATH,"/html/body/app-root/app-sign-in-layout/div/div/app-sign-in/app-content-container/div/div/div/form/div/button/span[1]"

        #定义用户名输入框
    def find_username(self):
         return self.get_element(self.username)

    #定义密码输入框
    def find_password(self):
         return self.get_element(self.password)

    #定义密码输入框
    def find_login_btn(self):
         return self.get_element(self.login_btn)


#定义操作层
class LoginHandle(BaseHandle):
    def __init__(self):
        self.login_page = LoginPage()

    #输入用户名
    @allure.step(title="输入手机号")
    def input_username(self,username):
        self.input_text(self.login_page.find_username(),username)

    #输入密码
    @allure.step(title="密码")
    def input_password(self,password):
        self.input_text(self.login_page.find_password(),password)

    #点击登录按钮
    @allure.step(title="点击登录按钮")
    def click_login_btn(self):
        self.login_page.find_login_btn().click()


#定义业务层
class LoginProxy:
    def __init__(self):
        self.login_handle = LoginHandle()
    #登录业务
    def login(self,username,password):
        #输入用户名
        self.login_handle.input_username(username)
        # 输入密码
        self.login_handle.input_password(password)
        # 点击登录按钮
        self.login_handle.click_login_btn()
        allure.attach(UtilsDriver.get_driver().get_screenshot_as_png(),"登录截图",allure.attachment_type.PNG)